<script>
    layui.use(['layer', 'form', 'element'], function () {
        var layer = layui.layer
        var $ = layui.jquery;
        var element = layui.element;
        $('[data-role="set_status"]').click(function () {
            var $this = $(this);
            var id = $this.closest('tr').find('input[name="ids"]').val();
            var status = $this.attr('data-status');
            var table = $this.closest('table').attr('data-table');
            status = status == 1 ? 0 : 1;
            $.post('{:url("setStatus")}', {id: id, status: status, table: table}, function (res) {
                if (res.code == 1) {
                    $this.attr('data-status', status);
                    $this.attr('class', 'layui-btn layui-btn-xs');
                    $this.addClass(status == 1 ? 'layui-btn-info' : 'layui-btn-danger');
                    $this.text(status == 1 ? '上线' : '下线');
                }
                ajax_result(res);
            })
        });

        function bind_delete() {
            $('[data-role="delete"]').click(function () {
                var $this = $(this);
                var id = $this.closest('tr').attr('data-id');
                if (id) {
                    layer.confirm('确定要删除该数据么？', {
                        btn: ['确定', '取消'] //按钮
                    }, function () {

                        var table = $this.attr('data-table');
                        $.post('{:url("setStatus")}', {id: id, status: -1, table: table}, function (res) {
                            if (res.code == 1) {
                                $this.closest('tr').fadeOut();
                            }
                            ajax_result(res);
                        })
                    }, function () {

                    });
                } else {
                    $this.closest('tr').fadeOut();
                }
            })
        }

        bind_delete();
    });


</script>